package com.kust.smarthome.web.controller;


import com.kust.smarthome.web.dto.PersonDetailsDto;
import com.kust.smarthome.web.model.PersonDetails;
import com.kust.smarthome.web.model.User;
import com.kust.smarthome.web.service.IRelationService;
import com.kust.smarthome.web.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.security.Principal;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author iAuzre
 * @since 2021-07-06
 */
@RestController
@RequestMapping("/relation")
@Api(value = "关系相关操作", tags = {"user-tag"})
public class RelationController {

    @Resource
    private IRelationService relationService;

    @Resource
    private IUserService userService;

    @GetMapping("/personDetailsList")
    @ApiOperation("关系人详细信息查询")
    public List<PersonDetails> findUser(Principal principal){

        User user = userService.getByUsername(principal.getName());

        return relationService.findPersonDetailsByUser(user.getId());
    }

}
